package InterfaceDemo;

interface Shape {
    public double Shape_PI = 3.14;
     
    public double area();
    public double perimeter();
}
 
class Circle implements Shape {
    private double radius;
     
    public Circle(double r) {
        setRadius(r);
    }
     
    public Circle() {
        this(10.0);
    }
     
    public double getRadius() {
        return radius;
    }
     
    public void setRadius(double r) {
        if (r > 0.0) {
            radius = r;
        }
        else {
            radius = 1;
        }
    }
     
    public double area() {
        return radius * radius * Shape_PI;
    }
     
    public double perimeter() {
        return 2 * radius * Shape_PI;
    } 
}
 
class Rectangle implements Shape {
    private double length;
    private double width;
     
    public Rectangle(double l, double w) {
        setLength(l);
        setWidth(w);
    }
     
    public Rectangle(double a) {
        this(a, 10.0);
    }
     
    public Rectangle() {
        this(10.0, 10.0);
    }
     
    public double getLength() {
        return length;
    }
     
    public double getWidth() {
        return width;
    }
     
    public void setLength(double l) {
        if (l > 0) {
            length = l;
        }
        else {
            length = 1.0;
        }
    }
     
    public void setWidth(double w) {
        if (w > 0) {
            width = w;
        }
        else {
            width = 1.0;
        }
    }
     
    public double area() {
        return length * width;
    }
     
    public double perimeter() {
        return 2 * (length + width);
    }
}
 
class InterfaceDemo {
    public static void main(String[] args) {
        Circle a = new Circle(15.6);
        System.out.println("圓的半徑是" + a.getRadius());
        System.out.println("圓的周長是" + a.perimeter());
        System.out.println("圓的面積是" + a.area());
         
        Rectangle b = new Rectangle(20.0, 16.0);
        System.out.println("長方形的長是" + b.getLength());
        System.out.println("長方形的寬是" + b.getWidth());
        System.out.println("長方形的周長是" + b.perimeter());
        System.out.println("長方形的面積是" + b.area());
    }
}